package com.leyou.auth.feign;

import com.leyou.auth.config.JwtProperties;
import com.leyou.auth.task.AppTokenHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 定义一个请求拦截器，在访问其他服务时，在请求头加上token
 */
@Component
public class PrivilegeInterceptor implements RequestInterceptor {
    @Autowired
    private JwtProperties jwtProperties;
    @Autowired
    private AppTokenHolder tokenHolder;

    @Override
    public void apply(RequestTemplate Template) {
        String token = tokenHolder.getToken();
        Template.header(jwtProperties.getApp().getHeaderName(),token);
    }
}
